package bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import DB.DB_connection_pool;

public class User_record {
	 
     public static double basketball_record;  //篮球历史记录
     public static double running_record;   //跑步历史记录
     public static double swimming_record;   //游泳历史记录
     
     
	public static double getBasketball_record(String user_account) {
		String select_user_data = "select * from user_data where user_account = '"+user_account+"'";
		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement ps_select= conn.prepareStatement(select_user_data);
			ResultSet rs = ps_select.executeQuery();
			
			if(rs.next()){
				basketball_record = rs.getDouble("basketball_record");
			}
			
			rs.close();
			ps_select.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return basketball_record;
	}
	public static void setBasketball_record(String user_account ,double basketball_record) {
		String up_data = "update user_data set basketball_record = '"+basketball_record+"' where user_account = '"+user_account+"'";

		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement up = conn.prepareStatement(up_data);
			up.executeUpdate();
			
			up.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		User_record.basketball_record = basketball_record;
	}
	public static double getRunning_record(String user_account) {
		String select_user_data = "select * from user_data where user_account = '"+user_account+"'";
		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement ps_select= conn.prepareStatement(select_user_data);
			ResultSet rs = ps_select.executeQuery();
			
			if(rs.next()){
				running_record = rs.getDouble("running_record");
			}
			
			rs.close();
			ps_select.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return running_record;
	}
	public static void setRunning_record(String user_account ,double running_record) {
		String up_data = "update user_data set running_record = '"+running_record+"' where user_account = '"+user_account+"'";

		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement up = conn.prepareStatement(up_data);
			up.executeUpdate();
			
			up.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		User_record.running_record = running_record;
	}
	public static double getSwimming_record(String user_account) {
		String select_user_data = "select * from user_data where user_account = '"+user_account+"'";
		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement ps_select= conn.prepareStatement(select_user_data);
			ResultSet rs = ps_select.executeQuery();
			
			if(rs.next()){
				swimming_record = rs.getDouble("swimming_record");
			}
			
			rs.close();
			ps_select.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return swimming_record;
	}
	public static void setSwimming_record(String user_account ,double swimming_record) {
		String up_data = "update user_data set swimming_record = '"+swimming_record+"' where user_account = '"+user_account+"'";

		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement up = conn.prepareStatement(up_data);
			up.executeUpdate();
			
			up.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		User_record.swimming_record = swimming_record;
	}
}
